package alo.p11.work;

/**
 * @ClassName MajorityNum
 * @Description 寻找数组中出现次数超过n/2的数
 * @Author Fanxc
 * @DATE 2021/3/14 10:00
 * @Version 1.0
 */
public class MajorityNum {
    int majorityNum(int[] A,int n){
        int majNum,count=0,element=-1;
        for (int i = 0; i < n; i++) {
            if (count==0){
                element=A[i];
                count=1;
            }else if (element==A[i]){
                count++;
            }else {
                count--;
            }
        }
        return element;
    }
}
